<?php

class Connection {
	
	private $host;
	private $user;
	private $pass;
	private $db;
	private $oCon;
	private $oDb;
	
	// constructor
	
	public function __construct($h, $u, $p, $d) {
		// print "I created a new Connection.";
		$this->host = $h;
		$this->user = $u;
		$this->pass = $p;
		$this->db = $d;
		$this->oCon = mysql_connect($this->host, $this->user, $this->pass) or die("Could not connect to database!");
		$this->oDb = mysql_select_db($this->db) or die("Could not select database!");
		register_shutdown_function(array(&$this, "close"));	// auto call function close() at the end of the page
	}
	
	// functions
	
	public function close() {
		// echo "Closing connection...";
		mysql_close($this->oCon);
	}
	
	public function isOpen() {
		if (!mysql_ping($this->oCon)) {
			throw new Exception("Could not connect to database!");
		}
		return true;
	}
	
} // end of class Connection

?>